/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
	"barge/app"
	"github.com/rs/zerolog/log"
	"github.com/spf13/cobra"
	"github.com/spf13/viper"
)

// exportCmd represents the version command
var exportCmd = &cobra.Command{
	Use:     "export",
	Aliases: []string{"save"},
	Short:   "整理配置信息",
	Long:    ``,
	Run: func(cmd *cobra.Command, args []string) {
		m, err := app.NewConfigManager(viper.GetString("configPath"))
		if err != nil {
			log.Err(err).Str("path", viper.GetString("configPath")).Send()
			return
		}
		m.Export()
		m.Path = exporterPath
		err = m.Save()
		if err != nil {
			log.Err(err).Str("path", exporterPath).Send()
			return
		}
	},
}

var exporterPath string

func init() {
	rootCmd.AddCommand(exportCmd)
	exportCmd.Flags().StringVarP(&exporterPath, "path", "p", "barge_export.toml", "导出配置文件的路径")
}
